package com.tanhua.server.controller;


import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.IMService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("messages")
public class IMController {

    private static final Logger LOGGER = LoggerFactory.getLogger(IMController.class);

//    @Autowired
//    private AnnouncementService announcementService;

    @Autowired
    private IMService imService;

//    /**
//     * 查询公告列表
//     */
//    @GetMapping("announcements")
//    @NoAuthorization
//    public ResponseEntity<PageResult> queryMessageAnnouncementList(@RequestParam(value = "page", defaultValue = "1") Integer page,
//                                                                   @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
//        page = page<1? 1: page;
//        IPage<Announcement> iPage = announcementService.queryList(page, pageSize);
//        PageResult pageResult = new PageResult();
//        pageResult.setPagesize(pageSize);
//        pageResult.setPage(page);
//        pageResult.setCounts(new Long(iPage.getTotal()).intValue());
//        pageResult.setPages(new Long(iPage.getPages()).intValue());
//        pageResult.setItems(iPage.getRecords());
//        for (Announcement o : iPage.getRecords() ) {
//            o.setCreateDate(new DateTime(o.getCreated()).toString("yyyy-MM-dd HH:mm"));
//        }
//        return ResponseEntity.ok(pageResult);
//    }


    /**
     * 添加联系人
     */
    @PostMapping("contacts")
    public ResponseEntity<Void> contactUser(@RequestBody Map<String, Object> param) {
        Long userId = Long.valueOf(param.get("userId").toString());
        return this.imService.contactUser(userId);
    }

    /**
     * 查询联系人列表
     */
    @GetMapping("contacts")
    public ResponseEntity<PageResult> queryContactsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                                        @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                                        @RequestParam(value = "keyword", required = false) String keyword) {
        return this.imService.queryContactsList(page, pageSize, keyword);
    }
//
//    /**
//     * 查询点赞列表
//     */
//    @GetMapping("likes")
//    public ResponseEntity<PageResult> queryMessageLikeList(@RequestParam(value = "page", defaultValue = "1") Integer page,
//                                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
//        PageResult pageResult = this.imService.queryMessageLikeList(page, pageSize);
//        return ResponseEntity.ok(pageResult);
//    }
//
//    /**
//     * 查询评论列表
//     */
//    @GetMapping("comments")
//    public ResponseEntity<PageResult> queryMessageCommentList(@RequestParam(value = "page", defaultValue = "1") Integer page,
//                                                              @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
//        PageResult pageResult = this.imService.queryMessageCommentList(page, pageSize);
//        return ResponseEntity.ok(pageResult);
//    }
//
//    /**
//     * 查询喜欢列表
//     */
//    @GetMapping("loves")
//    public ResponseEntity<PageResult> queryMessageLoveList(@RequestParam(value = "page", defaultValue = "1") Integer page,
//                                                           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
//        PageResult pageResult = this.imService.queryMessageLoveList(page, pageSize);
//        return ResponseEntity.ok(pageResult);
//    }
}
